You are here: Resources > Performance Tips > Order Conditions Sensibly

Order Conditions Sensibly

Conditions should be ordered sensibly, in order to reduce the selection set as quickly as possible.

If you need to identify features in a rule or action using more than one condition then you need to think about the order of these conditions. You will need to do this anywhere that you specify a class of objects other than in the rule or action’s root node (i.e. a For All, Existence, Aggregate, Chaining or Loop Over Objects construct within a rule or action).

The conditions are applied in the order in which they appear, which means that you need to order them so that the selection set is narrowed down as quickly as possible. Knowledge of the data will help to decide how to achieve this. Often a selection set is reduced using a spatial intersection or within distance check but sometimes there is another attribute which can be used to reduce the selection set.

Ensuring that the first condition uses an indexed value is the most important consideration (see Use Indexes), but it is also useful to consider the ordering of subsequent checks, based on either their complexity or ability to reduce the selection set.

For example, In a rule which reduces the selection set spatially, then performs a more detailed geometric comparison plus a simple attribute comparison, then it will be quickest to perform the attribute comparison second and the detailed geometric comparison third. The attribute comparison will be very fast, so it is worth doing this before the final complex geometric check in order to be able to easily reduce the number of complex geometric comparisons.

In the example shown below, the action sets a road centreline to be non-drivable if it is at least 90% within footpath polygons. Here we look at the classification string value before doing a more complex spatial comparison.

Put simple checks before complex checks.